﻿Imports MySql.Data.MySqlClient
Public Class Form2
    Dim con As MySqlConnection
    Dim cmd As MySqlCommand
    Dim reader As MySqlDataReader
    Dim result As Integer

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim con As New MySqlConnection("server=localhost;userid=root;password=;database=librarysys")
        Try
            con.Open()
            cmd = New MySqlCommand("select * from librarysys.tbluser where username='" & txtUser.Text & "' and password='" & txtPass.Text & "' ", con)
            reader = cmd.ExecuteReader
            While reader.Read
                result = result + 1
            End While
            If result = 1 Then

                MessageBox.Show("Access granted!")
                MDIParent1.Show()
                con.Close()
            Else
                MessageBox.Show("Access denied! Username and password do not match.")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Dispose()
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Application.Exit()
        Application.ExitThread()
    End Sub
End Class